package com.mhxy.service.impl;

import com.mhxy.constant.PicConstants;
import com.mhxy.handler.TaskProgressHandler;
import com.mhxy.service.AbstractTask;
import com.mhxy.util.FuzzyPicUtil;
import com.mhxy.util.ThreadUtil;
import com.sun.jna.platform.win32.WinDef;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class JianHuiTaskImpl extends AbstractTask {
    public JianHuiTaskImpl(WinDef.HWND hwnd_0) {
        super(hwnd_0);
    }

    @Override
    public Boolean before() throws Exception {
        return true;
    }

    @Override
    public Boolean execute() throws Exception {
        int count = 0;
        while (true) {
            count ++;
            clickEsc3();

            if (FuzzyPicUtil.findAndClickRandom(hwnd_0, PicConstants.剑会_天梯匹配, 1)) {
                ThreadUtil.sleep(5000);
            }

            if (FuzzyPicUtil.findAndClickRandom(hwnd_0, PicConstants.剑会_开始匹配, 1)) {
                ThreadUtil.sleep(5000);
            }

            if (FuzzyPicUtil.findPic(hwnd_0, PicConstants.剑会_匹配中, 1).isFinded()) {
                ThreadUtil.sleep(30000);
            }

            while (FuzzyPicUtil.findPic(hwnd_0, PicConstants.公共_战斗中, 1).isFinded()) {
                log.info("【{}】剑会战斗中...", getTaskName());
                ThreadUtil.sleep(30000);
            }

            TaskProgressHandler.updateProgress(getTaskName(), count + "次");
        }
    }

    @Override
    public Boolean after() throws Exception {
        return true;
    }

    @Override
    public String getTaskName() throws Exception {
        return "剑会";
    }
}
